﻿using M;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;

namespace EfClient
{

    internal class MContextFactory : IDesignTimeDbContextFactory<MContext>
    {
        public MContext CreateDbContext(string[] args)
        {
            // 此处写死，简单一点，读取配置文件比较复杂，只是为了迁移数据库
            string connStr = "Host=127.0.0.1;Port=5432;Database=efsimple;User ID=postgres;Password=sa*123;Pooling=true;MinPoolSize=10;MaxPoolSize=50;";
            DbContextOptionsBuilder<MContext> builder = new();
            builder.UseNpgsql(connStr,
                b => b.MigrationsAssembly("MClient")  // 这个必须有
                );
            MContext ctx = new MContext(builder.Options);
            return ctx;
        }
    }

}
